#ifndef GameManager_H
#define GameManager_H

#include <OISMouse.h>
#include <OISKeyboard.h>

#include <OgreRoot.h>
#include <OgreConfigFile.h>
#include <OgreRenderWindow.h>
#include <OgreFrameListener.h>
#include "OgreWindowEventUtilities.h"

//#include "Character.h"

#include "InputManager.h"
//#include "AudioManager.h"

class GameState;

class GameManager : public OIS::KeyListener, OIS::MouseListener, Ogre::FrameListener {
public:
    ~GameManager( void );

    void startGame( GameState *gameState );

    void changeState( GameState *gameState );
    void pushState( GameState *gameState );
    void popState( void );
    void requestShutdown( void );

    static GameManager* getSingletonPtr( void );

	/*
	void addCharacter( Character *character ) {
		characters.push_back( character );
	}

	void popCharacter( Character *character ) {
		std::vector<Character*> newvector;
		std::vector<Character*>::iterator it;
		it = characters.begin();
		while( it != characters.end()) {
			if( (*it)->getName() != character->getName() ) {
				newvector.push_back((*it));
			}
			it++;
		}
		characters = newvector;
	}

	Character * getCharacter( Ogre::String name ) {
		std::vector<Character*>::iterator it;
		it = characters.begin();
		while( it != characters.end()) {
			if( (*it)->getName() == name ) {
				return (*it);
			}
			it++;
		}
		return NULL;
	}
	*/

private:
    GameManager( void );
    GameManager( const GameManager& ) { }
    GameManager & operator = ( const GameManager& );

    bool configureGame( void );
    void setupResources( void );

    bool keyPressed( const OIS::KeyEvent &e );
    bool keyReleased( const OIS::KeyEvent &e );

    bool mouseMoved( const OIS::MouseEvent &e );
    bool mousePressed( const OIS::MouseEvent &e, OIS::MouseButtonID id );
    bool mouseReleased( const OIS::MouseEvent &e, OIS::MouseButtonID id );

	//bool frameStarted(const Ogre::FrameEvent &evt);
	//bool frameEnded(const Ogre::FrameEvent &evt);

    Ogre::Root         *mRoot;
    Ogre::RenderWindow *mRenderWindow;
    InputManager       *mInputMgr;
	//AudioManager	*mAudioMgr;
	//ISoundEngine	*mSoundEngine;

    GameState          *mIntroState;
    GameState          *mPlayState;
    GameState          *mPauseState;
	GameState			*mSokobanState;

	OIS::Mouse        *mMouse;
    OIS::Keyboard     *mKeyboard;

    bool bShutdown;
    std::vector<GameState*> mStates;
    static GameManager *mGameManager;

	//std::vector<Character*> characters;
};
#endif